<template>
  <a-drawer v-model:visible="LAYER.visible" :title="LAYER.title" :width="LAYER.width"
            :closable="LAYER.closable" :mask-closable="LAYER.maskClosable" :esc-to-close="LAYER.escToClose"
            :unmount-on-close="LAYER.unmountOnClose" :footer="LAYER.footer" :ok-text="LAYER.okText"
            :ok-loading="LAYER.okLoading" :cancel-text="LAYER.cancelText" :on-before-ok="onSubmit" @close="onCancel">
    <a-form ref="formRef" :model="formState" layout="vertical" :rules="REMIND_EDIT.RULES">
      <a-row :gutter="12">

        <a-col :span="24">
          <a-form-item label="提醒标题" field="title">
            <a-input v-model="formState.title" allow-clear placeholder="请填提醒标题"/>
          </a-form-item>
        </a-col>

        <a-col :span="24">
          <a-form-item label="用户群体" field="scope">
            <smart-dict :url="DictOptions.NoticeScope" v-model="formState.scope" is-radio :disabled="isUpdate"/>
          </a-form-item>
        </a-col>

        <a-col :span="24">
          <a-form-item label="收件人" field="recipientId">
            <a-input v-model="formState.recipientId" allow-clear placeholder="请填写收件人ID"/>
          </a-form-item>
        </a-col>



        <a-col :span="24">
          <a-form-item label="提醒正文" field="content" >
            <a-textarea v-model="formState.content" :max-length="500" placeholder="请设置提醒正文 500字以内"/>
          </a-form-item>
        </a-col>
      </a-row>


    </a-form>
    <!--表单结束-->
  </a-drawer>
</template>

<script lang="ts" setup>

import {EditDrawer} from '@/libs/core'

import {REMIND_EDIT} from "../resource/form";
import {SystemHttp} from '../resource/http'
import {DictOptions} from "@/libs/options";

const props = defineProps({record: {type: Object, required: true}})
const emit = defineEmits(['cancel'])

const {addRemind, updateRemind} = SystemHttp
const config = {tplRecord: REMIND_EDIT.BODY, rawRecord: props.record, rowKey: 'id', emit}

const service = new EditDrawer(config).setAddRequest(addRemind).setUpdateRequest(updateRemind)
const {formRef, formState, LAYER, isUpdate, onCancel, onSubmit} = service
LAYER.title = isUpdate ? '修改站内信' : '新建站内信'
</script>
